<?php
require_once('include/permiss.php');
require_once('config.php');
require_once('../include/convertm.php');
$order_id = $_GET['order_id'];
$pdo = $conn->prepare('SELECT order_id, datab_product.product_id, product_label, product_name, product_price, order_quantity FROM datab_order_product JOIN datab_product ON datab_order_product.product_id=datab_product.product_id  WHERE order_id=?');
$pdo->execute(array($order_id));
if ($pdo->rowCount()) {
    $data = $pdo->fetchAll();
}
$now = getdate();
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="design/css/default.css" />
<link rel="stylesheet" type="text/css" href="design/css/export.css" />
<div class='export'>
    <div class='logo'>eFood<font style='font-size: 12px; margin-left: 3px;'>restaurant</font></div>
    <div class='infobill'>
        <p><b style='font-size: 20px;'>HÓA ĐƠN BÁN HÀNG</b>
            <br/>Ngày <?php echo $now["mday"]; ?> tháng <?php echo $now["mon"]; ?> năm <?php echo $now["year"]; ?>
        </p>

    </div>

    <hr />
    <div class='customer'>
        <?php
        $pdo = $conn->prepare('SELECT customer_name, DATE_FORMAT(order_time, "%d/%m/%Y") AS order_time FROM datab_order WHERE order_id=? LIMIT 1');
        $pdo->execute(array($order_id));
        if ($pdo->rowCount()) {
            $customer = $pdo->fetchAll();
        }
        ?>

        <font>Tên khách hàng:&nbsp;<b><?php echo $customer[0]['customer_name']; ?></b></font>
        <br/><font>Địa chỉ:&nbsp;</font>
        <br/><font>Thời gian đặt hàng:&nbsp;<?php echo $customer[0]['order_time'] ?></font>
        <br/><br/>
    </div>
    <div class="bill">
        Số hóa đơn: #<?php echo $order_id; ?>
        <br/>Ngày in hóa đơn: <?php echo date("d-m-Y"); ?>
    </div>
    <div style='clear: both;'></div>
    <div class="box">
        <div class="box-content">
            <form method="post" action="#">
                <table class="list">
                    <tr bgcolor="#EFEFEF">
                        <th class='remove'>STT</th>
                        <th style='width:66px;'>Mã món ăn</th>
                        <th class="image">Món ăn</th>
                        <th class="remove">Số lượng</th>
                        <th class="quantity">Đơn giá</th>
                        <th class="quantity">Thành tiền</th>
                    </tr>
                    <?php
                    if (isset($data) && count($data)) {
                        $total = 0;
                        $i = 1;
                        foreach ($data as $row) {
                            $total += $row['order_quantity'] * $row['product_price'];
                            ?>
                            <tr>
                                <td class='remove'><?php echo $i; ?></td>
                                <td style='width:66px;'><?php echo $row['product_label']; ?></td>
                                <td class="name"><?php echo $row['product_name']; ?></td>
                                <td class="remove"><?php echo $row['order_quantity']; ?></td>
                                <td class="quantity"><?php echo formatMoney($row['product_price']); ?></td>
                                <td class="quantity"><?php echo formatMoney($row['order_quantity'] * $row['product_price']); ?></td>
                            </tr>
                            <?php
                            $i++;
                        }
                    }
                    ?>
                    <tr>
                        <td colspan='5'><font style='color: red; text-align: center;'>Tổng tiền</font></td>
                        <td class="quantity"><font style='color: red;'><?php echo formatMoney($total); ?></font></td>
                    </tr>                
                </table>
            </form>
        </div>
    </div> 

    <div style='margin-left: 11px;'>
        <font>Tổng tiền ghi bằng chữ:&nbsp;<b><?php echo convertNumberToWords($total); ?> (VNĐ)</b></font>
    </div>
    <div>
        <div>
            <div class='confimr1'><b>Nhân viên bán hàng</b><br/><i>Ký và ghi rõ họ tên</i></div>
            <div class='confimr2'><b>Khách hàng</b><br/><i>Ký và ghi rõ họ tên</i></div>
        </div>
    </div>

</div>



